#include <iostream>
using namespace std;

const int N = 100010;

long long n;
long long a[N];

int main()
{
    cin >> n;
    long long res = 0, t = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        t += a[i];
    }

    for (int i = 1; i <= n; i++)
        res = max(res, t - a[i] - a[i - 1] + a[i] * a[i - 1]);

    cout << res << endl;
    return 0;
}